package com.example.demo.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.dao.IndexDao;
import com.example.demo.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private IndexDao indexDao;

    @Override
    public  JSONObject addUser(JSONObject jsonObject){
        indexDao.addUser(jsonObject);
        JSONObject resultJson = new JSONObject();
        resultJson.put("returnCode", 0);
        resultJson.put("returnMsg", "添加成功");
        resultJson.put("returnData", "success");
        return resultJson;
    }

    @Override
    public JSONObject listUser(){
        List<JSONObject> list = indexDao.listUser();
        JSONObject returnData = new JSONObject();
        returnData.put("list", list);
        return returnData;
    }

    @Override
    public JSONObject updateUser(JSONObject jsonObject){
        indexDao.updateUser(jsonObject);
        JSONObject resultJson = new JSONObject();
        resultJson.put("returnCode", 0);
        resultJson.put("returnMsg", "更新成功");
        resultJson.put("returnData", "success");
        return resultJson;
    }

    @Override
    public JSONObject deleteUser(JSONObject jsonObject){
        indexDao.deleteUser(jsonObject);
        JSONObject resultJson = new JSONObject();
        resultJson.put("returnCode", 0);
        resultJson.put("returnMsg", "删除成功");
        resultJson.put("returnData", "success");
        return resultJson;
    }
}
